package logs;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

public class Log {
    //private FileWriter writer = null;
    private String filePath;

    public Log(String filePath) {
        this.filePath = filePath;
        /*if (LogManager.isEnabled()){
            try {
                writer = new FileWriter(filePath, true);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }*/
    }

    public void write(Object... message){
        if(/*writer == null || */!LogManager.isEnabled())
            return;

        synchronized (this){
            try {
                FileWriter writer = new FileWriter(filePath, true);

                writer.write(new Date().toString());
                writer.write(" - ");
                for(Object m : message){
                    if(m != null){
                        writer.write(m.toString());
                        writer.write(" ");
                    }
                }
                writer.write("\r\n");
                writer.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /*public void close(){
        if(writer != null)
        {
            try {
                synchronized (this){
                    writer.close();
                    writer = null;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }*/
}
